#include<bits/stdc++.h>
using namespace std;
int n,t,hs,key;
unsigned long long sum,a[11];
bool flag;
string str;
struct note
{
	unsigned long long x;
	unsigned long long y;
}b[30007];
unsigned long long hsh(unsigned long long xx)
{
	return xx%30007;
}
void fang(unsigned long long xx,unsigned long long yy)
{
	int i=hsh(xx);
	for (int j=i;j<=30006;j++)
	{
		if (b[j].x==0)
		{
			b[j].x=xx;
			b[j].y=yy;
			return;
		}
	}
}
int check(unsigned long long xx)
{
	int i=hsh(xx);
	for (int j=i;j<=30006;j++)
	{
		if (b[j].x==xx)
			return b[j].y;
	}
	return 0;
}
void cou()
{
	for (int i=1;i<=30006;i++)
	{
		cout<<b[i].x<<" ";
	}
	cout<<endl;
}
int main()
{
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	cin>>t;
	for(int i=1;i<=t;i++)
	{
		cin>>str;
		if (str=="Server")
		{
			cin>>str;
			a[1]=a[2]=a[3]=a[4]=a[5]=0;
			flag=false;
			for (int k=1;k<=5;k++)
			{
				if (str[0]=='0'&&str[1]!='.'&&str[1]!=':')
				{
					cout<<"ERR\n";
					flag=true;
					break;
				}
				do
				{
					a[k]=a[k]*10+(str[0]-'0');
					str.erase(0,1);
				}while (str[0]>='0'&&str[0]<='9');
				if (k>=1&&k<=4&&(a[k]<0||a[k]>255))
					{
						cout<<"ERR\n";
						flag=true;
						break;
					}
				if (k==5&&(a[k]<0||a[k]>65536))
					{
						cout<<"ERR\n";
						flag=true;
						break;
					}
				if (k>=1&&k<=3&&str[0]!='.')
					{
						cout<<"ERR\n";
						flag=true;
						break;
					}
				if (k==4&&str[0]!=':')
					{
						cout<<"ERR\n";
						flag=true;
						break;
					}
				str.erase(0,1);
				if (str[0]=='.'||str[0]==':')
				{
						cout<<"ERR\n";	
						flag=true;
						break;
				}
			}
			if (flag==false)
			{
				sum=0;
				for (int k=1;k<=5;k++)
				{
					while (a[k]!=0)
					{
						sum=sum*10+a[k]%10;
						a[k]/=10;
					}
				}
				if (check(sum))
					cout<<"FAIL\n";
				else 
				{
					cout<<"OK\n";
					fang(sum,i);
				}
			}
		}
		else
		{
			cin>>str;
			a[1]=a[2]=a[3]=a[4]=a[5]=0;
			flag=false;
			for (int k=1;k<=5;k++)
			{
				if (str[0]=='0'&&str[1]!='.'&&str[1]!=':')
				{
					cout<<"ERR\n";
					flag=true;
					break;
				}
				do
				{
					a[k]=a[k]*10+(str[0]-'0');
					str.erase(0,1);
				}while (str[0]>='0'&&str[0]<='9');
				if (k>=1&&k<=4&&(a[k]<0||a[k]>255))
					{
						cout<<"ERR\n";
						flag=true;
						break;
					}
				if (k==5&&(a[k]<0||a[k]>65536))
					{
						cout<<"ERR\n";
						flag=true;
						break;
					}
				if (k>=1&&k<=3&&str[0]!='.')
					{
						cout<<"ERR\n";
						flag=true;
						break;
					}
				if (k==4&&str[0]!=':')
					{
						cout<<"ERR\n";
						flag=true;
						break;
					}
				str.erase(0,1);
				if (str[0]=='.'||str[0]==':')
				{
						cout<<"ERR\n";	
						flag=true;
						break;
				}
			}
			if (flag==false)
			{
				sum=0;
				for (int k=1;k<=5;k++)
				{
					while (a[k]!=0)
					{
						sum=sum*10+a[k]%10;
						a[k]/=10;
					}
				}
				if (check(sum))
					cout<<check(sum)<<endl; 
				else cout<<"FAIL\n";
			}
		}
	}
	return 0;
 } 
 /*
10
Server 192.168.1.1:80
Client 192.168.1.1:80
Client 192.168.1.1:8080
Server 192.168.1.1:80
Server 192.168.1.1:8080
Server 192.168.1.999:0
Client 192.168.1.1.8080
Client 192.168.1.1:8080
Client 192.168.1.1:80
Client 192.168.1.999:0
*/
